﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "GcmpDevService.h"

namespace gcmp
{
    /// \brief 追溯调用的栈帧
    class GCMP_DEV_SERVICE_EXPORT CallStackHelper
    {
    public:
        /// \brief 获取指定范围内[beginFrameIndex,endFrameIndex)的调用栈帧信息，包含source file name 和 line number
        /// 例如：fun1->fun2->fun3->GcmpCallStackWorker::CallStack（->表示调用），则其调用的栈为:
        /// GcmpCallStackWorker::CallStack   index=0
        /// fun3                             index=1
        /// fun2                             index=2
        /// fun1                             index=3
        /// 则当GcmpCallStackWorker::CallStack(beginFrameIndex=3,endFrameIndex=4,...)时，获取到的为fun1的栈信息（左闭右开）
        /// 
        /// \param [in] beginFrameIndex 起始的栈帧索引
        /// \param [in] endFrameIndex 终止的栈帧索引
        ///
        /// \param [out] callStackInfo 返回的指定范围内的栈帧信息，包含source file name 和 line number
        /// \param [out] errorMessage 返回的错误信息。如果return value is true则errorMessage为空；否则返回调用出错的函数名和GetLastError的错误码
        /// 
        /// \return true:成功；false：失败
        static bool CallStack(
            int beginFrameIndex,
            int endFrameIndex,
            std::vector<std::wstring>& callStackInfo, 
            std::wstring& errorMessage,
            bool showfuncname = false
        );
    };
}
